//管理用户数据相关
import {defineStore} from "pinia";
import {ref} from "vue";
import {
    createOrderAPI,
    getDetailByOrderIdAPI,
    markOrderPaySuccessAPI,
    queryOrderByIdAPI,
    queryOrderByUserIdAPI
} from "@/api/orders";

export const useOrderStore=defineStore('order',()=>{
    const orderList=ref({})
    const orderById=ref({})
    const orderDetailList=ref({})
    const getOrderById = async (orderId) => {
        const res=await queryOrderByIdAPI(orderId)
        orderById.value=res
        return res;
    }

    const getDetailListByOrderId = async (orderId) => {
        const res=await getDetailByOrderIdAPI(orderId)
        orderDetailList.value=res;
        return res;
    }




    const getOrderList = async () => {
        const res=await queryOrderByUserIdAPI()
        orderList.value=res
        return res;
    }


    const saveOrders = async (orderFormDTO) => {
        const res=await createOrderAPI(orderFormDTO)
        console.log("调用",res)
        return res;
    }

    const markOrderPaySuccess=async (orderId)=>{
        const res=await markOrderPaySuccessAPI(orderId)
        return res
    }


    //3. 以对象的格式把state和action return
    return{
        orderList,
        orderById,
        orderDetailList,
        getDetailListByOrderId,
        getOrderById,
        saveOrders,
        markOrderPaySuccess,
        getOrderList,
    }
},{
    persist:true
})
